
//
//  UIImage+FileReader.swift
//  OneDay
//
//  Created by cheng xi on 2016/9/23.
//  Copyright © 2016年 xicheng. All rights reserved.
//

import UIKit

extension UIImage {
  
  static func fileRead(_ picName:String)->UIImage? {
    
    
    
    if let path = Bundle.main.path(forResource: picName + ( kDeviceScale == 2.0 ? "@2x" : "@3x"), ofType: "png") , let image = UIImage.init(contentsOfFile: path){
      return image
    }
    
    if let path = Bundle.main.path(forResource: picName + ( kDeviceScale == 2.0 ? "@3x" : "@2x"), ofType: "png") , let image = UIImage.init(contentsOfFile: path){
      return image
    }
    return nil
  }
  
  static func getUIImageWithColor(_ color:UIColor,andHeight h:CGFloat) -> UIImage? {
    let r = CGRect(x:0.0, y:0.0,width:1.0, height:h)
    UIGraphicsBeginImageContext(r.size)
    if let context = UIGraphicsGetCurrentContext() {
      context.setFillColor(color.cgColor)
      context.fill(r)
      let  img = UIGraphicsGetImageFromCurrentImageContext();
      UIGraphicsEndImageContext()
      return img
    }
    return nil
  }
  
}
